<?php
ob_start();
session_start();

	require ("main_function.php"); 
	require ("cek_session.php"); 
	
	if (empty($_POST['gen11'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 11 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen12'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 12 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen13'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 13 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen14'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 14 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen15'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 15 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen16'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 16 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen17'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 17 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen18'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 18 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen19'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 19 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen20'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 20 belum dipilih '.'\');';
		echo 'location.href = \'soal2.php\';';
		echo '</script>';
	}else{
	$pgl = array ($_POST['gen11'],$_POST['gen12'],$_POST['gen13'],$_POST['gen14'],$_POST['gen15'],$_POST['gen16'],$_POST['gen17'],$_POST['gen18'],$_POST['gen19'],$_POST['gen20']);
	for ($l=0;$l<=10;$l++)
		{
		if ($pgl[$l] == "A")
			{
			$A = $A + 1 ;
			}
		elseif ($pgl[$l] == "B")
			{
			$B = $B + 1;
			}
		elseif ($pgl[$l] == "C")
			{
			$C = $C + 1;
			}
		elseif ($pgl[$l] == "D")
			{
			$D = $D + 1;
			}
		}
	$cekisi="SELECT * FROM tkarakter where kdKarak='".$_SESSION["uid"]."'";
	$runcek=mysql_query($cekisi) or die(mysql_error());
	$num_query = mysql_affected_rows();
	$rec1=mysql_fetch_array($runcek);	
	if ($num_query == 0) {
		$isn="INSERT INTO tkarakter VALUES ('".$_SESSION["uid"]."','".$A."','".$B."','".$C."','".$D."')";
		$runisn=mysql_query($isn) or die("error".mysql_error());
		$num_query2 = mysql_affected_rows();
		if ($num_query2 == 1) {
			$date=date("Y")."-".date("n")."-".date("d");
			$isn2="INSERT INTO ttran_karak VALUES ('".$_SESSION["uid"]."','".$_SESSION["nm"]."','".$date."','".$A."','".$B."','".$C."','".$D."')";
			$runisn2=mysql_query($isn2) or die(mysql_error());
			$num_query3 = mysql_affected_rows();
			if ($num_query3 == 1) {
				header('location: soal2.php');
			}
		}
	}else{
		$tipe1=$rec1["tipe1"] + $A;
		$tipe2=$rec1["tipe2"] + $B;
		$tipe3=$rec1["tipe3"] + $C;
		$tipe4=$rec1["tipe4"] + $D;

		$isn="UPDATE tkarakter set tipe1='".$tipe1."', tipe2='".$tipe2."', tipe3='".$tipe3."', tipe4='".$tipe4."' where kdKarak='".$_SESSION["uid"]."'";
		$runisn=mysql_query($isn) or die("error".mysql_error());
		$num_query2 = mysql_affected_rows();
		if ($num_query2 == 1) {
			$date=date("Y")."-".date("n")."-".date("d");
			$isn2="UPDATE ttran_karak set tipe1='".$tipe1."', tipe2='".$tipe2."', tipe3='".$tipe3."', tipe4='".$tipe4."' where idSiswa='".$_SESSION["uid"]."'";
			$runisn2=mysql_query($isn2) or die(mysql_error());
			$num_query3 = mysql_affected_rows();
			if ($num_query3 == 1) {
				header('location: soal3.php');
			}
		}
	}
	}
	
mysql_close($konk);
ob_end_flush();
?>
